import React, { Component } from 'react'
import store from '../store'
import axios from 'axios'

export default class Home extends Component {
    // add = () => {
    //     store.dispatch({ type: "ADD" }) 
    // }
    // del = () => {
    //     store.dispatch({ type: "DEL" })
    // }
    render() {
        console.log(store.dispatch)
        return (
            <div>
                {
                    store.getState().list.map((item, index) => {
                        return <h3 key = { index }>
                            { item.name }
                        </h3>
                    })
                }
                {/* <button onClick = { this.add }>+</button>
                <h3>
                    Home -- { store.getState().count }
                </h3>
                <button onClick = { this.del }>--</button> */}
            </div>
        )
    }
    componentDidMount() {
        store.dispatch(() => {
            axios.get('/getList').then(res => {
                store.dispatch({ type: "GET_LIST", list: res.data.list })
            })
        })
    }
}
